<?php

namespace App\Http\Requests;


class SendSmsRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     *

     * @return array
     */

    public function rules()
    {
        $rules = [
            'type'=>'required|in:forget,register'
        ];
        if ($this->type == 'forget') {
            $rules['phone'] = 'required|regex:/^1[34578]\d{9}$/|exists:users';
        } else {
            $rules['phone'] = 'required|regex:/^1[34578]\d{9}$/|unique:users';
        }
        return $rules;
    }

    public function messages()
    {
        return [
            'type.required'=>['error_code'=>'F002002','message'=>'类型必须！'],
            'type.in'=>['error_code'=>'F002002','message'=>'类型不是指定的值！'],
            'phone.required'=>['error_code'=>'F002002','message'=>'手机号码必须！'],
            'phone.regex'=>['error_code'=>'F002003','message'=>'手机号码格式不正确！'],
            'phone.unique'=>['error_code'=>'F002004','message'=>'手机号码已存在！'],
            'phone.exists'=>['error_code'=>'F002001','message'=>'手机号码不存在！'],
        ];
    }
}
